class Daily < ActiveRecord::Base
  belongs_to :train

  def self.findFirstByDate
    find(
      :first,
      :order=>'date DESC'
    )
  end

  def self.findAllByDate date
    find(:all,
      :conditions => ['date = ?',date]
    )
  end

  def self.findDistinctDate
    find(
      :all,
      :select => "DISTINCT date",
      :order=>'date DESC'
    )
  end

  #得到最新的日期
  #返回值：Daily类型记录
  def self.findLastedDate
    find(
      :first,
      :order=>'date DESC'
    )
  end

  def self.findPage offset,limit
    find(:all,
      :offset => offset,
      :limit => limit,
      :order=>'date DESC'
    )
  end

  def self.countByDate date
    count(:conditions => ['date = ?',date])
  end

  def self.findPageByDate date,offset,limit
    find(
      :all,
      :offset => offset,
      :limit => limit,
      :conditions => ['date = ?',date]
    )
  end

  def self.findByDate date
    find(
      :all,
      :conditions => ['date = ?',date]
    )
  end

  def self.findByTrainIdAndDate trainId,date
    find(
      :first,
      :conditions => ['train_id = ? AND date = ?',trainId,date]
    )
  end

end
